package jw3.c2.controller;

<<<<<<< HEAD
=======
import com.mysql.jdbc.PreparedStatement;
>>>>>>> c99b46d54f58d393ceec8deeb74a45150477d89f
import jw3.c2.model.Rooms_type;
import jw3.c2.utils.DBConnection;

import java.sql.Connection;
<<<<<<< HEAD
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;
import java.util.Vector;

public class Rooms_typeController {
    //增
=======
import java.sql.ResultSet;
import java.util.Vector;

public class Rooms_typeController {
>>>>>>> c99b46d54f58d393ceec8deeb74a45150477d89f
    public static boolean register(Rooms_type rooms_type) {
        String sql="INSERT rooms_type VALUES(0,?,?,?,?,?)";
        return DBConnection.zsg(sql, rooms_type.getRoom_Type(),rooms_type.getRoom_Price(),rooms_type.getRoom_Img(),rooms_type.getR_D(),rooms_type.getR_S());

    }

    //删
    public static boolean logOut(int Rooms_Type_ID) {

        String sql="delete from rooms_type where Rooms_Type_ID=?";
        return DBConnection.zsg(sql,Rooms_Type_ID);
    }

    //改
    public static boolean edit(Rooms_type rooms_type) {
        String sql="update rooms_type set Room_Type=?, Room_Price=? where Rooms_Type_ID=?";

        return DBConnection.zsg(sql,rooms_type.getRoom_Type(),rooms_type.getRoom_Price(),rooms_type.getRooms_Type_ID());
    }

    public static Vector<Vector<Object>> getAll() {
        String sql = "SELECT * FROM rooms_type";
        //1、构造Vector类型用于赋值给表格
        Vector<Vector<Object>> data=new Vector<Vector<Object>>();
        try{
            Connection conn= DBConnection.getConnection();
<<<<<<< HEAD
            PreparedStatement ps=conn.prepareStatement(sql);
=======
            PreparedStatement ps= (PreparedStatement) conn.prepareStatement(sql);
>>>>>>> c99b46d54f58d393ceec8deeb74a45150477d89f
            ResultSet rs=ps.executeQuery();

            while (rs.next()){
                //创造对象，每次放一条数据
                Vector<Object> Rt =new Vector<Object>();
                //将每个字段放入对象
                Rt.add(rs.getInt("Rooms_Type_ID"));
                Rt.add(rs.getString("Room_Type"));
                Rt.add(rs.getDouble("Room_Price"));
                Rt.add(rs.getString("Room_Img"));
                Rt.add(rs.getInt("R_D"));
                Rt.add(rs.getString("R_S"));
//                Rt.add(rs.getString("Room_Image"));




                //每次将一条数据加入到集合
                data.add(Rt);

            }
            DBConnection.close(rs,ps,conn);
            return data;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

}
